$(function () {
    let $cont = $(".test-content");
    let $searchbtn = $("#btn-search");
    let $transferbtn = $("#btn-transfer");
    let $outbtn = $("#btn-out");
    let iPage = 1;
    let bIsLoadData = true;// 是否正在向后台加载数据

    $searchbtn.click(function () {
        let sCont = $cont.val();

        if (!sCont) {
            message.showError("查询值不能为空")
            return
        }

        let SdataParams = {
            "content": sCont,
        }
        $.ajax({
            url: '/akupdates/',
            type: 'POST',
            data: JSON.stringify(SdataParams),
            dataType: 'json',
        })
            .done(function (res) {
                if (res.errno === "0") {
                    if (iPage === 1) {
                        $("#tbody").html("")
                    }
                    res.data.pro_inf.forEach(function (one_contents) {
                        let content = `<tr data-id="${one_contents.id}" class="property_detail" id="light">
                                  <td>${one_contents.number}</td>
                                  <td>${one_contents.idcn__name}</td>
                                  <td>${one_contents.idcr__rname}</td>
                                  <td>${one_contents.pn}</td>
                                  <td>${one_contents.sn}</td>
                                  <td>${one_contents.mt}</td>
                                  <td>${one_contents.cb}</td>
                                  <td>${one_contents.ul}</td>
                                  <td>${one_contents.nip}</td>
                                  <td>${one_contents.mip}</td>
                                  <td>${one_contents.transfer}</td>
                                  <td>${one_contents.pupdate}</td>
                                  <td>${one_contents.obip}</td>
                                  <td>${one_contents.offline}</td>
                          </tr>`;
                        $(".search-box").append(content);
                    })
                } else {
                    message.showError(res.errmsg);
                }
            })
            .fail(function () {
                message.showError("服务器超时,请重试")
            })
    })


    $transferbtn.click(function () {
        let aKoption = $("#akupdate").val();
        let sCont = $cont.val();
        let sRemarks = $("#remarks").val();

        if (!aKoption) {
            message.showError("请选择更新字段")
            return
        }

        let SdataParams = {
            "options": aKoption,
            "content":sCont,
            "remarks":sRemarks,
        }
        $.ajax({
            url: '/akupdates/',
            type: 'PUT',
            data: JSON.stringify(SdataParams),
            dataType: 'json',
        })

            .done(function (res) {
                if (res.errno === "0") {
                    message.showSuccess("更新成功");
                    $searchbtn.click()
                } else {
                    message.showError(res.errmsg);
                    }
            })
            .fail(function () {
                message.showError("服务器超时,请重试")
            })


    })

    $outbtn.click(function () {
        let sCont = $cont.val();

        if (!sCont) {
            message.showError("无更新内容")
            return
        }

        let SdataParams = {
            "content":sCont,
        }
        $.ajax({
            url: '/akmoveout/',
            type: 'POST',
            data: JSON.stringify(SdataParams),
            dataType: 'json',
        })

            .done(function (res) {
                if (res.errno === "0") {
                    message.showSuccess("更新成功");
                    $searchbtn.click()
                } else {
                    message.showError(res.errmsg);
                    }
            })
            .fail(function () {
                message.showError("服务器超时,请重试")
            })


    })


})